import { computed } from 'vue';
import { useRouter } from 'vue-router';
import { ElMessage } from 'element-plus';
import { useUserStore } from '@/store/modules/user';
import {  Ticket, ShoppingBag, User, OfficeBuilding, UserFilled, Management } from '@element-plus/icons-vue';

/**
 * 菜单管理Hook
 * 处理导航菜单的状态和行为
 */
export function useMenu() {
  const router = useRouter();
  const userStore = useUserStore();

  // 根据用户类型获取对应的菜单
  const userMenus = computed(() => {
      const menus = [];
      
      if (userStore.userInfo.isLoggedIn) {
          const userType = userStore.userInfo.userType;
          
          // 普通用户菜单（userType: 1）
          if (userType === 1) {
              menus.push(
                  {
                      label: '我的需求',
                      icon: UserFilled,
                      route: '/my-demands'
                  },
                  {
                      label: '个人中心',
                      icon: User,
                      route: '/user-center'
                  }
              );
          }
          
          // 企业用户菜单（userType: 2）
          else if (userType === 2) {
              menus.push(
                  {
                      label: '需求大厅',
                      icon: Ticket,
                      route: '/demand-hall'
                  },
                  {
                      label: '订单中心',
                      icon: ShoppingBag,
                      route: '/order-center'
                  },
                  {
                      label: '员工管理',
                      icon: OfficeBuilding,
                      route: '/enterprise-manage'
                  }
              );
          }
          
          // 平台管理员菜单（userType: 3）
          else if (userType === 3) {
              menus.push(
                  {
                      label: '需求管理',
                      icon: Ticket,
                      route: '/demand-management'
                  },
                  {
                      label: '企业管理',
                      icon: OfficeBuilding,
                      route: '/enterprise-management'
                  },
                  {
                      label: '用户管理',
                      icon: User,
                      route: '/user-management'
                  }
              );
          }
      }
      
      return menus;
  });

  // 处理退出登录
  const handleLogout = () => {
      userStore.clearUserInfo();
      ElMessage.success('退出成功！');
      router.push('/');
  };

  return {
    userStore,
    userMenus,
    handleLogout
  };
}